package cn.xiaomubiao.oschine;

import android.support.v4.app.Fragment;

import cn.xiaomubiao.oschine.base.BaseEachFragment;
import cn.xiaomubiao.oschine.util.UIUtils;

/**
 * @author 张伟斌
 *         fragment 的简单工厂
 */

public class FragmentFactory {

    private static int classNames;

    // 根据不同position返回Fragment类
    public static Fragment createAdvanceFragment(int position) {

        String[] fragments = setFragmentClass(classNames);
        String clssStr = fragments[position];

        try {
            Class<?> clss = Class.forName(clssStr);
            BaseEachFragment fragment = (BaseEachFragment) clss.newInstance();

            return fragment;

        } catch (Exception e) {
            e.printStackTrace();

        }
        BaseEachFragment fragment = null;

        return fragment;
    }

    // 返回String.xml文件中的Fragment的类全路径名
    public static String[] setFragmentClass(int classNamess) {
        classNames = classNamess;

        return UIUtils.getStrings(classNames);

    }
}
